package demo1;

class Animal {

    public void eat(){
        System.out.println("吃饭");
    }
}

class Cat extends Animal{

    @Override
    public void eat(){
        System.out.println("吃鱼");
    }
}

class Dog extends Animal {

    @Override//重写的注解
    public void eat(){
        System.out.println("吃骨头");
    }
}

public class TestDemo1 {
    public static Dog dog(){
        return new Dog();
    }

    public static void main(String[] args) {
        Animal animal = new Cat();
        if (animal instanceof Dog) {
            Dog dog = (Dog)animal;
        }
        if (animal instanceof Cat) {
            Cat cat = (Cat)animal;
        }
    }
}

